﻿using System;
using System.Web.Mvc;
using System.Collections.Generic;

namespace WXY.Course.Common.MVCExtension
{
    public static class PagerExtension
    {
        private const int DEFAULT_PAGEBAR_LENGTH = 10;

        public static MvcHtmlString PageBar(this HtmlHelper htmlHelper, PageInfo pageInfo)
        {
            return PageBar(htmlHelper, pageInfo, DEFAULT_PAGEBAR_LENGTH, null);
        }

        public static MvcHtmlString PageBar(this HtmlHelper htmlHelper, PageInfo pageInfo, int pageBarLength)
        {
            return PageBar(htmlHelper, pageInfo, pageBarLength, null);
        }

        public static MvcHtmlString PageBar(this HtmlHelper htmlHelper, PageInfo pageInfo, int pageBarLength, object urlParams)
        {
            if (pageInfo == null) return null;

            var pageConfig = new PagerConfig(pageInfo, pageBarLength);
            var html = new WebUrlPager(htmlHelper, pageConfig, urlParams).Render();
            return new MvcHtmlString(html);
        }        
    }
}
